package tax.szz.socketd.demo1;

import org.noear.socketd.SocketD;
import org.noear.socketd.transport.core.Message;
import org.noear.socketd.transport.core.Session;
import org.noear.socketd.transport.core.entity.StringEntity;
import org.noear.socketd.transport.core.listener.SimpleListener;

import java.io.IOException;

public class ServerDemo {
    public static void main(String[] args) {
        try {
            SocketD.createServer("sd:tcp")
                    .config(config -> config.port(8602))
                    .listen(new SimpleListener() {
                        @Override
                        public void onMessage(Session session, Message message) throws IOException {
                            System.out.println(message);
                            session.send("/demo", new StringEntity("沈自在"));
                        }
                    }).start();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
